<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/templates/templateAdmin.xhtml">
	<ui:define name="conteudo">
	<p:growl autoUpdate="true" showDetail="true"/>
		<h:form>
			<p:dataTable var="professor" id="listarprofessor"
				value="#{mBProfessor.professores}"
				emptyMessage="Não há professors cadastrados" rows="10">
				<p:column filterBy="#{professor.usuario.matricula}" filterMatchMode="contains">
					<f:facet name="header">
						Matricula
					</f:facet>
					<p:commandLink value="#{professor.usuario.matricula}" oncomplete="professorDialog.show()" update="@form"> 
						<f:setPropertyActionListener target="#{mBProfessor.professorVizualizacao}" value="#{professor}"/>
					</p:commandLink>
				</p:column>
				<p:column filterBy="#{professor.usuario.nome}" filterMatchMode="contains">
					<f:facet name="header">
						Nome
					</f:facet>
					<p:commandLink value="#{professor.usuario.nome}" oncomplete="professorDialog.show()" update="@form"> 
						<f:setPropertyActionListener target="#{mBProfessor.professorVizualizacao}" value="#{professor}"/>
					</p:commandLink>
				</p:column>
				<p:column filterBy="#{professor.usuario.email}" filterMatchMode="contains">
					<f:facet name="header">
						Email
					</f:facet>
					<h:outputText value="#{professor.usuario.email}" />
				</p:column>
				<p:column filterBy="#{professor.telefone1}" filterMatchMode="contains">
					<f:facet name="header">
						Telefone 1
					</f:facet>
					<h:outputText value="#{professor.telefone1}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						Operações
					</f:facet>
					<p:commandButton value="Editar" ajax="false">
						<f:setPropertyActionListener target="#{mBProfessor.professor}"
							value="#{professor}" />
					</p:commandButton>
					<p:commandButton value="Excluir" oncomplete="confirmation.show()">
						<f:setPropertyActionListener target="#{mBProfessor.professor}"
							value="#{professor}" />
					</p:commandButton>


					<p:confirmDialog id="confirmDialog"
						message="Tem certeza que deseja excluir o professor?"
						header="Warning" severity="alert" widgetVar="confirmation">

						<p:commandButton id="confirm" value="Sim"
							oncomplete="confirmation.hide()" action="#{mBProfessor.excluir}"
							ajax="false" />

						<p:commandButton id="decline" value="Não"
							oncomplete="confirmation.hide()"
							action="#{mBProfessor.limpar}" />

					</p:confirmDialog>

				</p:column>
			</p:dataTable>
			<p:dialog widgetVar="professorDialog">
				<ui:include src="../../comum/professor.xhtml">
					<ui:param name="professor" value="#{mBProfessor.professorVizualizacao}"/>
				</ui:include>
			</p:dialog>
		</h:form>
		<p:panel header="Professor">
			<h:form id="formulario">
				<p:growl id="growl" showDetail="true" />
				<p:panel header="Dados Pessoais" toggleable="true">
					<h:panelGrid columns="2">
						<h:outputLabel value="Nome*:" />
						<p:inputText value="#{mBProfessor.professor.usuario.nome}"
							size="50" required="true" requiredMessage="Insira o nome"/>
						
						<h:outputLabel value="Nome do Pai*:" />
						<p:inputText value="#{mBProfessor.professor.nomePai}" required="true" requiredMessage="Insira o nome do pai" size="50"/>
						
						<h:outputLabel value="Nome da Mãe*:" />
						<p:inputText value="#{mBProfessor.professor.nomeMae}" required="true" requiredMessage="Insira o nome da mãe" size="50"/>
						
						<h:outputLabel value="Sexo*:" />
						<p:selectOneMenu value="#{mBProfessor.professor.sexo}" >
							<f:selectItem itemLabel="Masculino" itemValue="M" />
							<f:selectItem itemLabel="Feminino" itemValue="F" />
							<f:selectItem itemLabel="Indefinido" itemValue="I" />
							
						</p:selectOneMenu>
						
						<h:outputLabel value="Estado Cicil*:" />
						<p:selectOneMenu value="#{mBProfessor.professor.estadoCivil}" >
							<f:selectItem itemLabel="Solteiro(a)" itemValue="SOLTEIRO" />
							<f:selectItem itemLabel="Casado(a)" itemValue="CASADO" />
							<f:selectItem itemLabel="Viúvo(a)" itemValue="VIUVO" />
							<f:selectItem itemLabel="Divorciado(a)" itemValue="DIVORCIADO" />
						</p:selectOneMenu>
						
						<h:outputLabel value="Raça*:" />
						<p:selectOneMenu value="#{mBProfessor.professor.raca}" >
							<f:selectItem itemLabel="Negro" itemValue="NEGRO" />
							<f:selectItem itemLabel="Caucasiano" itemValue="Caucasiano" />
							<f:selectItem itemLabel="Pardo" itemValue="Pardo" />
							<f:selectItem itemLabel="Asiático" itemValue="Asiatico" />
						</p:selectOneMenu>
						
						<h:outputLabel value="Tipo Sanguineo:" />
						<p:inputText value="#{mBProfessor.professor.tipoSanquineo}" size="4"/>

						<h:outputLabel value="Senha*:"
							rendered="#{mBProfessor.professor.id == NULL}" />
						<p:password rendered="#{mBProfessor.professor.id == NULL}"
							value="#{mBProfessor.professor.usuario.senha}" required="true" requiredMessage="Insira a senha"/>
						<h:outputLabel rendered="#{mBProfessor.professor.id == NULL}"
							value="Repetir Senha*:" />
						<p:password rendered="#{mBProfessor.professor.id == NULL}"
							value="#{mBProfessor.senhaRepetida}" required="true" requiredMessage="Insira a senha repetida"/>

						
					</h:panelGrid>
				</p:panel>
				
				<p:panel header="Documentos" toggleable="true">
					<h:panelGrid columns="2">
					<h:outputLabel value="RG*:" />
					<p:inputMask mask="999.999.999" value="#{mBProfessor.professor.rg}" required="true" requiredMessage="Insira o RG" size="10"/>
					
					<h:outputLabel value="CPF*:" />
					<p:inputMask mask="999.999.999-99" value="#{mBProfessor.professor.usuario.cpf}" required="true" requiredMessage="Insira o RG" size="10"/>
					
					<h:outputLabel value="Orgão Expeditor*:" />
					<p:inputText value="#{mBProfessor.professor.orgaoExpeditorRg}" required="true" requiredMessage="Insira o orgão expeditor do RG" size="4"/>
				
					<h:outputText value="UF*:" />
					<p:selectOneMenu value="#{mBProfessor.professor.ufRg}">
						<f:selectItems value="#{mBProfessor.estados}" var="estado" itemLabel="#{estado}" itemValue="#{estado}"/>
					</p:selectOneMenu>
					
					<h:outputLabel value="Título de Eleitor*:" />
					<p:inputMask value="#{mBProfessor.professor.titulo}" size="12" mask="9999.9999.9999" required="true" requiredMessage="Insira o titulo"/>
					
					<h:outputLabel value="Zona*:" />
					<p:inputText value="#{mBProfessor.professor.zonaTitulo}" size="12" required="true" requiredMessage="Insira a zona do titulo"/>
					
					<h:outputLabel value="Seção*:" />
					<p:inputText value="#{mBProfessor.professor.secao}" size="12" required="true" requiredMessage="Insira a seção do titulo"/>
					
					<h:outputText value="UF do Título*:" />
					<p:selectOneMenu value="#{mBProfessor.professor.ufTitulo}">
						<f:selectItems value="#{mBProfessor.estados}" var="estado" itemLabel="#{estado}" itemValue="#{estado}"/>
					</p:selectOneMenu>
					</h:panelGrid>	
				</p:panel>
				<p:panel header="Dados Bancarios" toggleable="true">
				<h:panelGrid columns="2">
					<h:outputLabel value="Banco*:" />
					<p:inputText value="#{mBProfessor.professor.banco}" required="true" requiredMessage="Inisira o banco" size="20"/>
					
					<h:outputLabel value="Comta*:" />
					<p:inputText value="#{mBProfessor.professor.conta}" required="true" requiredMessage="Inisira a conta" size="10"/>
					
					<h:outputLabel value="Agencia*:" />
					<p:inputText value="#{mBProfessor.professor.banco}" required="true" requiredMessage="Inisira a Agencia" size="10"/>
				
				</h:panelGrid>
				
				</p:panel>
				<p:panel header="Contatos" toggleable="true">
					<h:panelGrid columns="2">
						<h:outputLabel value="Telefone 1*:" />
						<p:inputMask mask="(99)9999-9999" size="11"
							value="#{mBProfessor.professor.telefone1}" required="true" requiredMessage="Insira o telefone"/>
						<h:outputLabel value="Telefone 2:" />
						<p:inputMask mask="(99)9999-9999" size="11"
							value="#{mBProfessor.professor.telefone2}" />
						
						<h:outputLabel value="Email*:" />
						<p:inputText value="#{mBProfessor.professor.usuario.email}" size="50"
							validatorMessage="Email inválido" required="true" requiredMessage="Insira o emial">
							<f:validateRegex
								pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
						</p:inputText>
					</h:panelGrid>
				</p:panel>
				<p:panel header="Endereço" toggleable="true">
					<h:panelGrid columns="2">
						<h:outputLabel value="Cep:" />
						<p:inputMask value="#{mBProfessor.professor.cep}" size="8"
							mask="99999-999" />
						<h:outputLabel value="Rua:" />
						<p:inputText value="#{mBProfessor.professor.endereco}" size="60" />
						<h:outputLabel value="Número:" />
						<p:inputText value="#{mBProfessor.professor.numero}" size="4" />
						<h:outputLabel value="Bairro:" />
						<p:inputText value="#{mBProfessor.professor.bairro}" />
						
						
						
						
						<h:outputLabel value="Estado" />
						<p:selectOneMenu value="#{mBProfessor.professor.estado}">
							<f:selectItem itemValue="" itemLabel="---"/>
							<f:selectItems value="#{mBProfessor.estados}" var="estado" itemLabel="#{estado}" itemValue="#{estado}" />
							<p:ajax event="change" listener="#{mBProfessor.carregarCidades()}" update="Cidades"/>
						</p:selectOneMenu>
						
						<h:outputLabel value="Cidade:" />
						<p:selectOneMenu id="Cidades" value="#{mBProfessor.professor.cidade}">
							<f:selectItems value="#{mBProfessor.cidades}" var="estado" itemLabel="#{estado}" itemValue="#{estado}" />
							
						</p:selectOneMenu>
						
					</h:panelGrid>
				</p:panel>
				
				<p:panel id="escolhaEscola" header="Escola" toggleable="true">
					<h:outputLabel value="Escola:" />
					<p:autoComplete dropdown="true" value="#{mBProfessor.escola}"
						completeMethod="#{mBEscola.complete}" />

					<p:commandButton value="Adicionar Escola"
						action="#{mBProfessor.adicionarEscola}" update="escolhaEscola growl"/>

					<p:dataTable id="tabelaEscola" var="escola"
						value="#{mBProfessor.professor.escolas}"
						emptyMessage="Nenhuma escola foi vinculada a este professor ainda!">

						<p:column headerText="Nome da escola">
								#{escola.nome}
							</p:column>

						<p:column headerText="Inscrição da escola">
								#{escola.sigla}
							</p:column>

						<p:column headerText="Remover" id="coluna">
							<p:commandButton value="Remover escola" id="botao"
								process="@this" ajax="false">
								<p:collector value="#{escola}"
									removeFrom="#{mBProfessor.professor.escolas}" />
							</p:commandButton>
						</p:column>


					</p:dataTable>

				</p:panel>
				<h:panelGroup rendered="#{mBProfessor.professor.id == NULL}">
					<p:commandButton value="Cadastrar" ajax="false"
						action="#{mBProfessor.cadastrar}" />
					<p:commandButton value="Cancelar" ajax="false" />
				</h:panelGroup>
				<h:panelGroup rendered="#{mBProfessor.professor.id != NULL}">
					<p:commandButton value="Editar" ajax="false"
						action="#{mBProfessor.editar}" />
					<p:commandButton onclick="form.reset()" value="Cancelar" ajax="false"
						action="#{mBProfessor.limpar}" />
				</h:panelGroup>
			</h:form>
		</p:panel>
	</ui:define>
</ui:composition>
</html>